﻿namespace OboutInc
{
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.IO;
    using System.Reflection;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Caching;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class oboutAJAXPage : Page, IAJAX
    {
        private string __viewstateId;
        private OboutInc.ClientManager _ClientManager;
        private Literal _scriptPlaceHolder;
        private bool _updateAllPanels = true;
        internal bool IsScriptRegistered;
        private Callback pb1;
        private Hashtable registeredScripts = new Hashtable();
        private object third;
        private Hashtable updatePanelParams;
        internal ArrayList updatePanels = new ArrayList();

        public void CancelTimer(string id)
        {
            string script = "ob_post_cancelTimer(\"" + id.Replace("\"", "\\\"") + "\")";
            if (this.IsCallback)
            {
                this.ExecBeforeLoad(script);
            }
            else
            {
                this.ExecOnLoad(script);
            }
        }

        public void CreateTimer(string id, string functionToCall, int interval)
        {
            string script = string.Concat(new object[] { "ob_post_createTimer(\"", id.Replace("\"", "\\\""), "\",\"", functionToCall.Replace("\"", "\\\""), "\", ", interval, ")" });
            if (this.IsCallback)
            {
                this.ExecBeforeLoad(script);
            }
            else
            {
                this.ExecOnLoad(script);
            }
        }

        public void CreateTimer(string id, string serverFunctionToCall, string clientFunctionToCall, int interval)
        {
            if (clientFunctionToCall == null)
            {
                clientFunctionToCall = "function(){}";
            }
            string script = string.Concat(new object[] { "ob_post_createTimer(\"", id.Replace("\"", "\\\""), "\",\"ob_post.post(null, '", serverFunctionToCall.Replace("\"", "\\\"").Replace("'", @"\'"), "',", clientFunctionToCall.Replace("\"", "\\\""), ")\", ", interval, ")" });
            if (this.IsCallback)
            {
                this.ExecBeforeLoad(script);
            }
            else
            {
                this.ExecOnLoad(script);
            }
        }

        protected override NameValueCollection DeterminePostBackMode()
        {
            if (this.IsCallback)
            {
                return base.Request.Form;
            }
            return base.DeterminePostBackMode();
        }

        public void EndResponse()
        {
            if (!this.IsCallback)
            {
                base.Response.End();
            }
            else
            {
                this.pb1.WriteResponse(true);
            }
        }

        public void ExecBeforeLoad(string script)
        {
            this.pb1.WriteScriptOnBeforeLoad(script);
        }

        public void ExecOnLoad(string script)
        {
            this.pb1.WriteScriptOnLoad(script, true);
        }

        public override Control FindControl(string id)
        {
            Control control = this.myFindControl(this, id, true);
            if (control != null)
            {
                return control;
            }
            control = base.FindControl(id);
            if (control != null)
            {
                return control;
            }
            for (Control control2 = this.NamingContainer; control2 != null; control2 = control2.NamingContainer)
            {
                control = control2.FindControl(id);
                if (control != null)
                {
                    return control;
                }
            }
            return null;
        }

        private Control findControlByType(Type type, ControlCollection controls)
        {
            Control control = null;
            for (int i = 0; i < controls.Count; i++)
            {
                Control o = controls[i];
                if (type.IsInstanceOfType(o))
                {
                    return o;
                }
                control = this.findControlByType(type, o.Controls);
                if (control != null)
                {
                    return control;
                }
            }
            return control;
        }

        private CallbackPanel FindPanel(string panelId, Control container)
        {
            CallbackPanel panel = null;
            foreach (Control control in container.Controls)
            {
                if ((control is CallbackPanel) && ((control.ID == panelId) || (control.ClientID == panelId)))
                {
                    return (CallbackPanel) control;
                }
                panel = this.FindPanel(panelId, control);
                if (panel != null)
                {
                    return panel;
                }
            }
            return null;
        }

        public ScriptResponse GetNewScriptResponse(bool keepLast)
        {
            return this.pb1.GetNewScriptResponse(keepLast);
        }

        private void HandleScriptRegistration(string key, string script, bool AtStartUp)
        {
            if (!this.IsCallback)
            {
                if (!this.registeredScripts.ContainsKey(key))
                {
                    this.registeredScripts.Add(key, null);
                }
                if (AtStartUp)
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), key, script);
                }
                else
                {
                    base.ClientScript.RegisterClientScriptBlock(base.GetType(), key, script);
                }
            }
            else
            {
                script = script.Replace("\r\n", "").Replace("\t", "").Replace("\r", "").Replace("\n", "");
                if (script.Length > 0)
                {
                    object[] objArray = this.parseForElements(script, true, false);
                    ArrayList list = (ArrayList) objArray[1];
                    if (((list.Count <= 0) || !this.registeredScripts.ContainsKey(key)) || ((((object[]) list[0])[0].ToString() == "t") && (((string[]) ((object[]) list[0])[1])[2].Length != 0)))
                    {
                        ScriptResponse newScriptResponse = this.GetNewScriptResponse(AtStartUp);
                        newScriptResponse.WriteResponse(objArray);
                        if (AtStartUp)
                        {
                            newScriptResponse.WriteScript("ob_post_addContentToPageSection(response.content,\"body\",req_id)");
                        }
                        else
                        {
                            newScriptResponse.WriteScript("ob_post_addContentToPageSection(response.content,\"head\",req_id)");
                        }
                    }
                }
            }
        }

        private void InitializeComponent()
        {
            base.Load += new EventHandler(this.LoadCallbackData);
        }

        private void LoadCallbackData(object sender, EventArgs e)
        {
            try
            {
                if (!new ScriptManagerHelper(this).IsInAsyncCallback && ((this.pb1.Event != null) && (this.pb1.Event.Length != 0)))
                {
                    MethodInfo[] methods;
                    string nameAddOn = string.Empty;
                    if ((this.pb1.Event == "UpdatePanel") && this.pb1.Values.Contains("panelId"))
                    {
                        nameAddOn = this.pb1.Values["panelId"].ToString();
                    }
                    else if (!this.IsFormPost && (this.pb1.Values["CSRFCheck"] != null))
                    {
                        nameAddOn = this.pb1.Values["CSRFCheck"].ToString();
                        this.pb1.Values.Remove("CSRFCheck");
                    }
                    if (this.AllowCSRFCheck && !this.PostCookie(nameAddOn).Equals(base.Request.Cookies["OBPostCookie" + nameAddOn].Value))
                    {
                        throw new CSRFException();
                    }
                    bool flag = false;
                    bool flag2 = false;
                    if ((this.pb1.Event == "UpdatePanelOnPostback") && (this.pb1.Values.Count > 0))
                    {
                        flag = true;
                        flag2 = true;
                    }
                    if ((this.pb1.Event == "UpdatePanel") || (this.pb1.Event == "UpdateAllPanels"))
                    {
                        this.UpdatePanelParams = new Hashtable(this.pb1.Values);
                        foreach (string str2 in this.UpdatePanelParams.Keys)
                        {
                            if ((str2 != "panelId") && (str2 != "containerId"))
                            {
                                this.pb1.Values.Remove(str2);
                            }
                        }
                    }
                    if (this.pb1.Event.IndexOf(":") > 0)
                    {
                        string id = this.pb1.Event.Substring(0, this.pb1.Event.IndexOf(":"));
                        string str4 = this.pb1.Event.Substring(this.pb1.Event.IndexOf(":") + 1);
                        Control control = this.FindControl(id);
                        while ((control != null) && (str4.IndexOf(":") > 0))
                        {
                            id = str4.Substring(0, str4.IndexOf(":"));
                            str4 = str4.Substring(this.pb1.Event.IndexOf(":") + 1);
                            control = control.FindControl(id);
                        }
                        Type type = null;
                        if (control != null)
                        {
                            type = control.GetType();
                        }
                        if (type != null)
                        {
                            methods = type.GetMethods();
                            for (int i = 0; i < methods.Length; i++)
                            {
                                if (methods[i].Name == str4)
                                {
                                    flag = true;
                                    ParameterInfo[] parameters = methods[i].GetParameters();
                                    object[] objArray = new object[parameters.Length];
                                    if (parameters.Length >= this.pb1.Values.Count)
                                    {
                                        int num2 = 0;
                                        for (int j = 0; j < parameters.Length; j++)
                                        {
                                            if (this.pb1.Values.Contains(parameters[j].Name))
                                            {
                                                try
                                                {
                                                    if ((this.pb1.Values[parameters[j].Name] == null) && (parameters[j].ParameterType == typeof(object)))
                                                    {
                                                        objArray[j] = null;
                                                    }
                                                    else
                                                    {
                                                        TypeConverter converter = TypeDescriptor.GetConverter(this.pb1.Values[parameters[j].Name].GetType());
                                                        if (parameters[j].ParameterType.IsInterface)
                                                        {
                                                            objArray[j] = this.pb1.Values[parameters[j].Name];
                                                        }
                                                        else if (converter.CanConvertTo(parameters[j].ParameterType))
                                                        {
                                                            objArray[j] = converter.ConvertTo(this.pb1.Values[parameters[j].Name], parameters[j].ParameterType);
                                                        }
                                                        else
                                                        {
                                                            objArray[j] = Convert.ChangeType(this.pb1.Values[parameters[j].Name], parameters[j].ParameterType);
                                                        }
                                                    }
                                                }
                                                catch (Exception exception)
                                                {
                                                    throw new InvalidCastException(exception.Message + @" \r\nParameter '" + parameters[j].Name + "' should be " + parameters[j].ParameterType.Name + ".");
                                                }
                                                num2++;
                                            }
                                        }
                                        if (num2 == this.pb1.Values.Count)
                                        {
                                            flag2 = true;
                                            this._updateAllPanels = false;
                                            object obj2 = null;
                                            obj2 = methods[i].Invoke(control, objArray);
                                            if (obj2 != null)
                                            {
                                                this.pb1.Write(obj2);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!flag)
                    {
                        methods = base.GetType().GetMethods();
                        for (int k = 0; k < methods.Length; k++)
                        {
                            if (methods[k].Name == this.pb1.Event)
                            {
                                flag = true;
                                ParameterInfo[] infoArray3 = methods[k].GetParameters();
                                object[] args = new object[infoArray3.Length];
                                if (infoArray3.Length >= this.pb1.Values.Count)
                                {
                                    int num5 = 0;
                                    for (int m = 0; m < infoArray3.Length; m++)
                                    {
                                        if (this.pb1.Values.Contains(infoArray3[m].Name))
                                        {
                                            try
                                            {
                                                if ((this.pb1.Values[infoArray3[m].Name] == null) && (infoArray3[m].ParameterType == typeof(object)))
                                                {
                                                    args[m] = null;
                                                }
                                                else
                                                {
                                                    TypeConverter converter2 = TypeDescriptor.GetConverter(this.pb1.Values[infoArray3[m].Name].GetType());
                                                    if (infoArray3[m].ParameterType.IsInterface)
                                                    {
                                                        args[m] = this.pb1.Values[infoArray3[m].Name];
                                                    }
                                                    else if (converter2.CanConvertTo(infoArray3[m].ParameterType))
                                                    {
                                                        args[m] = converter2.ConvertTo(this.pb1.Values[infoArray3[m].Name], infoArray3[m].ParameterType);
                                                    }
                                                    else
                                                    {
                                                        args[m] = Convert.ChangeType(this.pb1.Values[infoArray3[m].Name], infoArray3[m].ParameterType);
                                                    }
                                                }
                                            }
                                            catch (Exception exception2)
                                            {
                                                throw new InvalidCastException(exception2.Message + @" \r\nParameter '" + infoArray3[m].Name + "' should be " + infoArray3[m].ParameterType.Name + ".");
                                            }
                                            num5++;
                                        }
                                    }
                                    if (num5 == this.pb1.Values.Count)
                                    {
                                        flag2 = true;
                                        this._updateAllPanels = false;
                                        object obj3 = base.GetType().InvokeMember(this.pb1.Event, BindingFlags.InvokeMethod, null, this, args);
                                        if (obj3 != null)
                                        {
                                            this.pb1.Write(obj3);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (!flag)
                    {
                        if (base.Master != null)
                        {
                            MethodInfo[] infoArray4 = base.Master.GetType().GetMethods();
                            for (int n = 0; n < infoArray4.Length; n++)
                            {
                                if (infoArray4[n].Name == this.pb1.Event)
                                {
                                    flag = true;
                                    ParameterInfo[] infoArray5 = infoArray4[n].GetParameters();
                                    object[] objArray3 = new object[infoArray5.Length];
                                    if (infoArray5.Length >= this.pb1.Values.Count)
                                    {
                                        int num8 = 0;
                                        for (int num9 = 0; num9 < infoArray5.Length; num9++)
                                        {
                                            if (this.pb1.Values.Contains(infoArray5[num9].Name))
                                            {
                                                try
                                                {
                                                    if ((this.pb1.Values[infoArray5[num9].Name] == null) && (infoArray5[num9].ParameterType == typeof(object)))
                                                    {
                                                        objArray3[num9] = null;
                                                    }
                                                    else
                                                    {
                                                        TypeConverter converter3 = TypeDescriptor.GetConverter(this.pb1.Values[infoArray5[num9].Name].GetType());
                                                        if (infoArray5[num9].ParameterType.IsInterface)
                                                        {
                                                            objArray3[num9] = this.pb1.Values[infoArray5[num9].Name];
                                                        }
                                                        else if (converter3.CanConvertTo(infoArray5[num9].ParameterType))
                                                        {
                                                            objArray3[num9] = converter3.ConvertTo(this.pb1.Values[infoArray5[num9].Name], infoArray5[num9].ParameterType);
                                                        }
                                                        else
                                                        {
                                                            objArray3[num9] = Convert.ChangeType(this.pb1.Values[infoArray5[num9].Name], infoArray5[num9].ParameterType);
                                                        }
                                                    }
                                                }
                                                catch (Exception exception3)
                                                {
                                                    throw new InvalidCastException(exception3.Message + @" \r\nParameter '" + infoArray5[num9].Name + "' should be " + infoArray5[num9].ParameterType.Name + ".");
                                                }
                                                num8++;
                                            }
                                        }
                                        if (num8 == this.pb1.Values.Count)
                                        {
                                            flag2 = true;
                                            this._updateAllPanels = false;
                                            object obj4 = base.Master.GetType().InvokeMember(this.pb1.Event, BindingFlags.InvokeMethod, null, base.Master, objArray3);
                                            if (obj4 != null)
                                            {
                                                this.pb1.Write(obj4);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (!flag)
                        {
                            throw new NotImplementedException("Could not find a method named '" + this.pb1.Event + "'.");
                        }
                    }
                    if (!flag2)
                    {
                        throw new NotImplementedException("Could not find a method named '" + this.pb1.Event + "' with the specified parameters.");
                    }
                }
            }
            catch (NotImplementedException exception4)
            {
                this.ThrowException("ServerMethodNotImplemented", exception4.Message);
            }
            catch (TargetInvocationException exception5)
            {
                if (exception5.InnerException.GetType().Name != "ThreadAbortException")
                {
                    this.ThrowException(exception5.InnerException.GetType().Name, exception5.InnerException.Message);
                }
            }
            catch (CSRFException)
            {
                this.ThrowException("CSRFException", "Invalid Callback! CSRF Attack!");
            }
            catch (Exception exception6)
            {
                this.ThrowException(exception6);
            }
        }

        protected override object LoadPageStateFromPersistenceMedium()
        {
            if (!this.IsCallback && (!base.IsPostBack || (this.__viewstateId == null)))
            {
                return base.LoadPageStateFromPersistenceMedium();
            }
            object obj2 = null;
            if ((this.__viewstateId != null) && this.__viewstateId.StartsWith("__viewState_"))
            {
                obj2 = this.Page.Cache.Get(this.__viewstateId);
                if (this.IsCallback && (obj2 is Triplet))
                {
                    this.third = ((Triplet) obj2).Third;
                    ((Triplet) obj2).Third = null;
                }
                this.Page.Cache.Remove(this.__viewstateId);
            }
            return obj2;
        }

        private Control myFindControl(Control container, string id, bool up)
        {
            Control control = null;
            if (!string.IsNullOrEmpty(id))
            {
                string[] strArray = id.Split(new char[] { ':' });
                foreach (Control control2 in container.Controls)
                {
                    if (control2.ID == strArray[0])
                    {
                        if (strArray.Length == 1)
                        {
                            control = control2;
                        }
                        else
                        {
                            control = this.myFindControl(control2, string.Join(":", strArray, 1, strArray.Length - 1), false);
                        }
                    }
                    if (control == null)
                    {
                        control = this.myFindControl(control2, id, false);
                    }
                    if (control != null)
                    {
                        break;
                    }
                }
                if ((up && (control == null)) && (container.NamingContainer != null))
                {
                    return this.myFindControl(container.NamingContainer, id, up);
                }
            }
            return control;
        }

        protected override void OnInit(EventArgs e)
        {
            if (new ScriptManagerHelper(this).IsInAsyncCallback)
            {
                base.OnInit(e);
            }
            else
            {
                base.Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(this.Validate), null);
                this.ClientManager.Scripts.Clear();
                this.ClientManager.ScriptFiles.Clear();
                this.ClientManager.StyleFiles.Clear();
                this.pb1 = new Callback(this);
                if (base.Request.Params["getScript"] != null)
                {
                    base.Response.ContentType = "text";
                    base.Response.Cache.SetCacheability(HttpCacheability.Public);
                    base.Response.Write(this.pb1.readScriptFromResource());
                    base.Response.End();
                }
                base.OnInit(e);
                this.InitializeComponent();
                if (this.IsCallback && (this.pb1.Values["__VIEWSTATE_ID"] != null))
                {
                    this.__viewstateId = this.pb1.Values["__VIEWSTATE_ID"].ToString();
                    this.pb1.Values.Remove("__VIEWSTATE_ID");
                }
                else if ((base.IsPostBack && (this.Page.Request.Form["__VIEWSTATE_ID"] != null)) && this.Page.Request.Form["__VIEWSTATE_ID"].StartsWith("__viewState_"))
                {
                    this.__viewstateId = this.Page.Request.Form["__VIEWSTATE_ID"];
                }
                if (this.pb1.Event == "ViewStateTouchCache")
                {
                    this.SavePageStateToPersistenceMedium(this.LoadPageStateFromPersistenceMedium());
                    this.pb1.WriteResponse(true);
                }
                else
                {
                    if (this.IsCallback)
                    {
                        this.registeredScripts = (this.Session[base.Request.RawUrl] != null) ? ((Hashtable) this.Session[base.Request.RawUrl]) : new Hashtable();
                    }
                    this.OnInitUpdateOnPostback();
                }
            }
        }

        private void OnInitUpdateOnPostback()
        {
            if (this.pb1.Event == "UpdatePanelOnPostback")
            {
                object[] args = new object[] { this.PostFormCallbackPanelId };
                object obj2 = base.GetType().InvokeMember(this.pb1.Event, BindingFlags.InvokeMethod, null, this, args);
                if (obj2 != null)
                {
                    this.pb1.Write(obj2);
                }
            }
        }

        public void OpenWindow(string url)
        {
            this.OpenWindow(url, null, null, null);
        }

        public void OpenWindow(object url, object name)
        {
            this.OpenWindow(url, name, null, null);
        }

        public void OpenWindow(object url, object name, object extraOptions)
        {
            this.OpenWindow(url, name, extraOptions, null);
        }

        public void OpenWindow(object url, object name, object extraOptions, object replaceHistory)
        {
            this.pb1.WriteScriptOnBeforeLoad("var win=window.open(" + (((("\"" + ((url != null) ? url.ToString().Replace("\"", "") : "") + "\", ") + "\"" + (((name != null) && (name.ToString().Length > 0)) ? name.ToString().Replace("\"", "") : "") + "\", ") + "\"" + (((extraOptions != null) && (extraOptions.ToString().Length > 0)) ? extraOptions.ToString().Replace("\"", "") : "") + "\"") + (((replaceHistory != null) && (replaceHistory is bool)) ? (", " + replaceHistory.ToString().ToLower()) : "")) + ");if(win!=null){try{win.focus();}catch(e){}}else alert(\"The window could not be opened. If you have any pop-up blocker active, try deactivating it.\");");
        }

        public object[] parseForElements(string content, bool replace, bool addPlaceHolders)
        {
            ArrayList list = new ArrayList();
            Regex regex = new Regex(@"((?<head><(?<type>((script)|(style)))[^>]*?>)(?<content>.*?)</\2>)|(?<head><(?<type>link)[^>]*?>)", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            foreach (Match match in regex.Matches(content))
            {
                string str4;
                string str8;
                string str13 = match.Groups["type"].Value.ToLower().Trim();
                if (str13 != null)
                {
                    if (!(str13 == "script"))
                    {
                        if (str13 == "style")
                        {
                            goto Label_015B;
                        }
                        if (str13 == "link")
                        {
                            goto Label_026B;
                        }
                    }
                    else
                    {
                        string str = match.Groups["content"].Value;
                        string str2 = new Regex("src\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
                        string str3 = new Regex("language\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
                        list.Add(new object[] { "t", new string[] { str3, str2, str } });
                    }
                }
                continue;
            Label_015B:
                str4 = match.Groups["content"].Value;
                string str5 = new Regex("type\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
                string str6 = new Regex("media\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
                string str7 = new Regex("title\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
                list.Add(new object[] { "s", new string[] { str5, str6, str7, str4 } });
                continue;
            Label_026B:
                str8 = new Regex("type\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
            string str9 = new Regex("rel\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
            string str10 = new Regex("title\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
            string str11 = new Regex("href\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
            string str12 = new Regex("display\\s*?=\\s*?((\"|')?)(?<value>[^\\1>]+?)(\\1)(\\s|>)", (RegexOptions)0x11).Match(match.Groups["head"].Value).Groups["value"].Value;
                list.Add(new object[] { "l", new string[] { str8, str9, str10, str11, str12 } });
            }
            if (replace)
            {
                content = regex.Replace(content, addPlaceHolders ? "<span id=\"obpb_${type}\"></span>" : "");
            }
            return new object[] { content, list };
        }

        public string PostCookie(string nameAddOn)
        {
            if (base.Request.Headers["OBPostCookie" + nameAddOn] == null)
            {
                return "NoHeaderCookieAvailable";
            }
            return base.Request.Headers["OBPostCookie" + nameAddOn];
        }

        public void Redirect(string url)
        {
            this.Redirect(url, false);
        }

        public void Redirect(string url, bool endResponse)
        {
            if (!this.IsCallback)
            {
                base.Response.Redirect(url, endResponse);
            }
            else
            {
                this.pb1.ClearScriptResponses();
                this.pb1.GetNewScriptResponse(false);
                this.pb1.GetNewScriptResponse(false);
                this.pb1.Write(url);
                this.pb1.WriteScriptOnBeforeLoad("document.location.href=response.content;response.allowReturn=false;");
                if (endResponse)
                {
                    this.pb1.WriteResponse(true);
                }
            }
        }

        public override void RegisterClientScriptBlock(string key, string script)
        {
            this.HandleScriptRegistration(key, script, false);
        }

        private void RegisterCustomScripts()
        {
            string script = "window.ob_ScriptToRegister = function(){";
            foreach (string str2 in this.ClientManager.Scripts.Values)
            {
                script = script + str2 + ";";
            }
            script = script + "}";
            this.ExecOnLoad(script);
            if (this.ClientManager.ScriptFiles.Values.Count > 0)
            {
                foreach (string str3 in this.ClientManager.ScriptFiles.Keys)
                {
                    this.ExecOnLoad("ob_post.register_script('" + str3 + "', '" + this.ClientManager.ScriptFiles[str3].ToString() + "');");
                }
            }
            if (this.ClientManager.StyleFiles.Values.Count > 0)
            {
                foreach (string str4 in this.ClientManager.StyleFiles.Keys)
                {
                    this.ExecOnLoad("ob_post.register_style('" + str4 + "', '" + this.ClientManager.StyleFiles[str4].ToString() + "');");
                }
            }
        }

        public override void RegisterHiddenField(string hiddenFieldName, string hiddenFieldInitialValue)
        {
            if (!this.IsCallback)
            {
                if (!this.registeredScripts.ContainsKey("hiddenfield_" + hiddenFieldName))
                {
                    this.registeredScripts.Add("hiddenfield_" + hiddenFieldName, null);
                }
                base.ClientScript.RegisterHiddenField(hiddenFieldName, hiddenFieldInitialValue);
            }
            else
            {
                ScriptResponse newScriptResponse = this.GetNewScriptResponse(false);
                newScriptResponse.WriteResponse(hiddenFieldInitialValue);
                if (!this.registeredScripts.ContainsKey("hiddenfield_" + hiddenFieldName))
                {
                    newScriptResponse.WriteScript("ob_post_createHiddenField(\"" + hiddenFieldName + "\", response.content);");
                }
                else
                {
                    newScriptResponse.WriteScript("try{document.getElementById(\"" + hiddenFieldName + "\").value = response.content;}catch(e){}");
                }
            }
        }

        public void RegisterScript(string ScriptKey, string Script)
        {
            this.ClientManager.RegisterScript(ScriptKey, Script);
        }

        public void RegisterScriptFile(string ScriptFileKey, string ScriptFilePath)
        {
            this.ClientManager.RegisterScriptFile(ScriptFileKey, ScriptFilePath);
        }

        public override void RegisterStartupScript(string key, string script)
        {
            this.HandleScriptRegistration(key, script, true);
        }

        public void RegisterStyleFile(string StyleFileKey, string StyleFilePath)
        {
            this.ClientManager.RegisterStyleFile(StyleFileKey, StyleFilePath);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (new ScriptManagerHelper(this).IsInAsyncCallback)
            {
                base.Render(writer);
                return;
            }
            if (this.IsCallback)
            {
                base.Render(writer);
                this.RegisterCustomScripts();
                if (this.IsCallback)
                {
                    this.pb1.RenderControl(writer);
                    return;
                }
                return;
            }
            StringWriter writer2 = new StringWriter();
            HtmlTextWriter writer3 = new HtmlTextWriter(writer2);
            string str = "";
            if (!this.IsCallback)
            {
                this.pb1.RenderControl(writer3);
                writer3.Flush();
                str = writer2.ToString();
                writer2 = new StringWriter();
                writer3 = new HtmlTextWriter(writer2);
            }
            if (this.ScriptPlaceHolder == null)
            {
                if (!(str != ""))
                {
                    goto Label_00DA;
                }
                HtmlGenericControl child = new HtmlGenericControl("AJAXPageScript") {
                    InnerHtml = str
                };
                try
                {
                    this.Page.Header.Controls.Add(child);
                    goto Label_00DA;
                }
                catch (NullReferenceException)
                {
                    throw new Exception("Add the runat=\"server\" attribute to your head section: <head runat=\"server\">");
                }
            }
            this.ScriptPlaceHolder.Text = str;
        Label_00DA:
            base.Render(writer);
            this.RegisterCustomScripts();
            this.pb1.RenderOnLoadScript(writer);
            this.Session[base.Request.RawUrl] = this.registeredScripts;
        }

        protected override void SavePageStateToPersistenceMedium(object viewState)
        {
            if ((this.EnableCallbackViewState && !this.IsCallback) && !base.IsPostBack)
            {
                this.__viewstateId = "__viewState_" + Guid.NewGuid().ToString();
            }
            if (((this.__viewstateId != null) && (this.__viewstateId.Length > 0)) && (viewState != null))
            {
                if (this.IsCallback && (viewState is Triplet))
                {
                    if ((((Triplet) viewState).Third is ArrayList) && (this.third is ArrayList))
                    {
                        ((ArrayList) ((Triplet) viewState).Third).AddRange((ArrayList) this.third);
                    }
                    else
                    {
                        ((Triplet) viewState).Third = this.third;
                    }
                }
                this.Page.Cache.Add(this.__viewstateId, viewState, null, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.Normal, null);
                this.ExecOnLoad("ob_post_setPageViewStateId(\"" + this.__viewstateId + "\")");
            }
            if (!this.IsCallback)
            {
                base.SavePageStateToPersistenceMedium(viewState);
            }
        }

        public void SetValue(string controlId, string value)
        {
            this.pb1.WriteScriptOnBeforeLoad("ob_post_setValue(\"" + controlId.Replace("\"", "") + "\", \"" + value.Replace("\"", "\\\"") + "\")");
        }

        public void ShowAlert(string text)
        {
            this.pb1.WriteScriptOnBeforeLoad("alert(\"" + text.Replace("\"", "\\\"") + "\")");
        }

        public void ShowConfirmationDialog(string text, string methodToCall)
        {
            this.ShowConfirmationDialog(text, methodToCall, new Hashtable());
        }

        public void ShowConfirmationDialog(string text, string methodToCall, Hashtable extraParameters)
        {
            this.pb1.Write(extraParameters);
            this.pb1.WriteScriptOnBeforeLoad("ob_post.AddParam(\"response\", window.confirm(\"" + text + "\"));for(key in response.content){ob_post.AddParam(key, response.content[key])};ob_post.post(null, \"" + methodToCall.Replace("\"", "") + "\", response.funcToExec);response.allowReturn=false;");
            this.EndResponse();
        }

        private void ThrowException(Exception ex)
        {
            this.pb1.ThrowException(ex.GetType().Name, ex.Message.Replace("\"", "\\\""));
        }

        private void ThrowException(string ExceptionType, string ExceptionMessage)
        {
            this.pb1.ThrowException(ExceptionType, ExceptionMessage.Replace("\"", "\\\""));
        }

        public void UpdateAllPanels()
        {
            this._updateAllPanels = true;
            this.UpdatePanelsInContainer(this);
        }

        public void UpdatePanel(string panelId)
        {
            CallbackPanel panel = this.FindPanel(panelId, this);
            if (panel != null)
            {
                panel.Update();
            }
        }

        public void UpdatePanel(string panelId, string containerId)
        {
            CallbackPanel panel = this.FindPanel(panelId, this);
            if (panel != null)
            {
                panel.UpdateIn(containerId);
            }
        }

        public void UpdatePanelOnPostback(string callbackPanelId)
        {
            this.UpdatePanel(callbackPanelId);
        }

        private void UpdatePanelsInContainer(Control container)
        {
            foreach (Control control in container.Controls)
            {
                if (control is CallbackPanel)
                {
                    ((CallbackPanel) control).Update();
                }
                this.UpdatePanelsInContainer(control);
            }
        }

        public void Validate(HttpContext context, object data, ref HttpValidationStatus status)
        {
            if (context.Request.QueryString["getScript"] != null)
            {
                status = HttpValidationStatus.Valid;
            }
            else
            {
                status = HttpValidationStatus.Invalid;
            }
        }

        public bool AllowCSRFCheck
        {
            get
            {
                if (this.ViewState["AllowCSRFCheck"] == null)
                {
                    return false;
                }
                return (bool) this.ViewState["AllowCSRFCheck"];
            }
            set
            {
                this.ViewState["AllowCSRFCheck"] = value;
            }
        }

        internal OboutInc.ClientManager ClientManager
        {
            get
            {
                if (this._ClientManager == null)
                {
                    this._ClientManager = new OboutInc.ClientManager();
                }
                return this._ClientManager;
            }
        }

        [Browsable(false)]
        public string ComponentVersion
        {
            get
            {
                return ("1." + Constants.version_year.ToString() + "." + Constants.version_month.ToString() + "." + Constants.version_number.ToString());
            }
        }

        public bool ContainsServerForm
        {
            get
            {
                foreach (Control control in this.Controls)
                {
                    if (control is HtmlForm)
                    {
                        return true;
                    }
                }
                return false;
            }
        }

        public bool EnableCallbackViewState
        {
            get
            {
                if (this.ViewState["EnableCallbackViewState"] == null)
                {
                    return false;
                }
                return (bool) this.ViewState["EnableCallbackViewState"];
            }
            set
            {
                this.ViewState["EnableCallbackViewState"] = value;
            }
        }

        public bool EnableSessionKeepAlive
        {
            get
            {
                if (this.ViewState["EnableSessionKeepAlive"] == null)
                {
                    return false;
                }
                return (bool) this.ViewState["EnableSessionKeepAlive"];
            }
            set
            {
                this.ViewState["EnableSessionKeepAlive"] = value;
            }
        }

        internal Callback InternalPB1
        {
            get
            {
                return this.pb1;
            }
        }

        public bool IsCallback
        {
            get
            {
                return ((base.Request.Headers["OBPostReq"] != null) && (base.Request.Headers["OBPostReq"] == "true"));
            }
        }

        public bool IsFormPost
        {
            get
            {
                return ((base.Request.Headers["OBPostFormReq"] != null) && (base.Request.Headers["OBPostFormReq"] == "true"));
            }
        }

        public bool IsSyncCallback
        {
            get
            {
                return ((base.Request.Headers["OBPostSync"] != null) && (base.Request.Headers["OBPostSync"] == "true"));
            }
        }

        public bool IsUpdateAllPanels
        {
            get
            {
                return this._updateAllPanels;
            }
        }

        public string PostFormCallbackPanelId
        {
            get
            {
                if (this.Page.Request["ob_post_callbackPanelId"] == null)
                {
                    return null;
                }
                return this.Page.Request["ob_post_callbackPanelId"].ToString();
            }
        }

        public int RequestTimeoutMilliseconds
        {
            get
            {
                if (this.ViewState["RequestTimeoutMilliseconds"] == null)
                {
                    return 0x1d4c0;
                }
                return (int) this.ViewState["RequestTimeoutMilliseconds"];
            }
            set
            {
                this.ViewState["RequestTimeoutMilliseconds"] = value;
            }
        }

        public Literal ScriptPlaceHolder
        {
            get
            {
                return this._scriptPlaceHolder;
            }
            set
            {
                this._scriptPlaceHolder = value;
            }
        }

        [Description("The default page to send data to if none specified as argument to ob_post.post method.")]
        public string ServerFileName
        {
            get
            {
                string str = (string) this.ViewState["ServerFileName"];
                if (str == null)
                {
                    try
                    {
                        return base.Request.RawUrl.Substring(base.Request.RawUrl.IndexOf(base.Request.Path.Substring(base.Request.Path.LastIndexOf("/") + 1)));
                    }
                    catch
                    {
                        string serverFileNameNoParams = this.ServerFileNameNoParams;
                        if (base.Request.QueryString.Count > 0)
                        {
                            serverFileNameNoParams = serverFileNameNoParams + "?" + base.Request.QueryString.ToString();
                        }
                        return serverFileNameNoParams;
                    }
                }
                return str;
            }
            set
            {
                this.ViewState["ServerFileName"] = value;
            }
        }

        internal string ServerFileNameNoParams
        {
            get
            {
                try
                {
                    return base.Request.Path;
                }
                catch
                {
                    return (base.GetType().Name + ".aspx");
                }
            }
        }

        public string SessionCookieName
        {
            get
            {
                if (this.ViewState["SessionCookieName"] == null)
                {
                    return "ASP.NET_SessionId";
                }
                return (string) this.ViewState["SessionCookieName"];
            }
            set
            {
                this.ViewState["SessionCookieName"] = value;
            }
        }

        public bool SessionIsExpired
        {
            get
            {
                bool flag = false;
                if ((this.Context.Session != null) && this.Session.IsNewSession)
                {
                    string str = base.Request.Headers["Cookie"];
                    flag = (str != null) && (str.IndexOf(this.SessionCookieName) >= 0);
                }
                return flag;
            }
        }

        [DefaultValue(true), Description("Specifies whether alerts should be shown at client side if there are errors.")]
        public bool ShowErrorsAtClient
        {
            get
            {
                object obj2 = this.ViewState["ShowErrorsAtClient"];
                return ((obj2 == null) || ((bool) obj2));
            }
            set
            {
                this.ViewState["ShowErrorsAtClient"] = value;
            }
        }

        [Description("Specifies whether exceptions should be thrown at client side if there are errors."), DefaultValue(false)]
        public bool ThrowExceptionsAtClient
        {
            get
            {
                object obj2 = this.ViewState["ThrowExceptionsAtClient"];
                if (obj2 == null)
                {
                    return false;
                }
                return (bool) obj2;
            }
            set
            {
                this.ViewState["ThrowExceptionsAtClient"] = value;
            }
        }

        public Hashtable UpdatePanelParams
        {
            get
            {
                return this.updatePanelParams;
            }
            set
            {
                this.updatePanelParams = value;
            }
        }
    }
}

